package org.company.earth.service.impl;

import java.util.Random;

import org.company.earth.service.IScheduleService;

public class HelloScheduleService implements IScheduleService {
    
    private Integer count;
    
    private Integer MAX;
    
    public HelloScheduleService() {
        count = new Integer(0);
        MAX = new Random().nextInt(15);
    }
    
    private void sleep() {
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    
    @Override
    public boolean call() {
        count++;
        String str = String.format("idCard=%d,count=%d", this.hashCode(),count);
        System.out.println(str);
        sleep();
        return isSuccess();
    }

    public boolean isSuccess() {
        if(count >= MAX) {
            return true;
        }
        return false;
    }
}
